home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 11 / More Recursion Examples / C-curve < prev    next >
Text File  |  1993-11-03  |  2KB  |  69 lines

  1. { This programs difines a recrsive subroutine to
  2.   draw "C-curves".  A C-curve is a path from A to
  3.   B that is formed by replacing straight line segments
  4.   with "detours" shaped (roughly) like a "C":
  5.  
  6.     A                   C       A
  7.       |                  -------
  8.       |                  |
  9.       |     becomes      |
  10.       |                  | D
  11.       |                  |
  12.       |                  |
  13.       |                  -------
  14.     B                   E        B
  15.  
  16.   The program also defines a subroutine TestC that
  17.   can be called to draw sample C-curves.  TestC
  18.   is called once at the end of the program.
  19. }
  20.  
  21.  
  22. SUB C(distance,complexity)
  23.    IF complexity = 0 THEN
  24.       forward(distance)
  25.    ELSE
  26.       turn(-90)
  27.       C(distance/2, complexity-1)
  28.       turn(90)
  29.       C(distance/2, complexity-1)
  30.       C(distance/2, complexity-1)
  31.       turn(90)
  32.       C(distance/2, complexity-1)
  33.       turn(-90)
  34.    END IF
  35. END SUB
  36.  
  37.  
  38. SUB TestC
  39.  
  40.  { This subroutine can be called to draw sample C-curves;
  41.    the user is asked to specify the complexity and a
  42.    C-curve of that complexity is drawn stretch down most 
  43.    of the screen. }
  44.  
  45.    DECLARE complexity
  46.  
  47.    penUp
  48.    MoveTo(3,4.5)
  49.    penDown
  50.    face(-90)
  51.    clear
  52.  
  53.    AskUser("What level of complexity do you want (0 to 10)?", complexity)
  54.  
  55.    complexity := trunc(complexity)  { Make sure value is OK }
  56.    IF complexity < 0 THEN
  57.       complexity := 0
  58.       TellUser("Using complexity = 0.")
  59.    END IF
  60.    IF complexity > 10 THEN
  61.       complexity := 10
  62.       TellUser("Using complexity 10.")
  63.    END IF
  64.  
  65.    C(9,complexity)
  66.  
  67. END SUB
  68.  
  69. TestC